#import "SEGRegisterManager.h"
#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif

#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif
static id _registerManager;
static dispatch_once_t onceToken;

@implementation SEGRegisterManager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _registerManager = [[self alloc] init];
    });
    return _registerManager;
}

+(void)destroyResource{
    onceToken = 0;
    _registerManager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----
-(void)requestRegisterWithSmscode:(NSString*)smsCode password:(NSString*)password communityId:(NSString*)communityId randomToken:(NSString*)randomToken tel:(NSString*)tel completed:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))completed{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:smsCode forKey:@"smsCode"];
    [params setValue:password forKey:@"password"];
    [params setValue:communityId forKey:@"communityId"];
    [params setValue:randomToken forKey:@"randomToken"];
    [params setValue:tel forKey:@"tel"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-sso/v1/userApp/register",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed || result == nil) {
            completed(NO,nil,codeType,error.localizedDescription);
            return;
        }
        
        if (![result isKindOfClass:[NSDictionary class]]) {
            completed(NO,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.register_ = [SEGRegisterModel yy_modelWithDictionary:result];
        completed(YES,result,codeType,error.localizedDescription);
        return;
    }];
}
#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(SEGRegisterModel *)register_{
    if (!_register_) {
        _register_ = [[SEGRegisterModel alloc]init];
    }
    return _register_;
}
#pragma mark - GETTER----END----
@end
